window.onload = function () {

    function getid(a) {
        return document.getElementById(a);
    }

    getid("teamname").onfocus = function () {
        getid("alerttitle").innerHTML = "";

        getid("teamname").style.borderColor="red";
    };
    getid("teamname").onchange = function () {
        document.getElementById("alerttitle").innerHTML = "";
        var regu = "^[a-zA-Z\u4e00-\u9fa5]+$";
        var re = new RegExp(regu);
        var ss = getid("teamname").value;
        if (!re.test(ss)) {
            document.getElementById("alerttitle").innerHTML = "您的输入错误,只能输入中文和英文";
            for (var i = 0; i < ss.length; i++) {
                if (!re.test(ss[i])) {
                    ss = ss.replace(ss[i], "");
                    i = i - 1;
                }

            }
            document.getElementById("teamname").value = "" + ss;
        }
        if (ss.length < 15) {
            document.getElementById("alerttitle").innerHTML = "您的输入字数太少";
        }

    }

    /*价格验证*/
    function isPriceNumber(_keyword) {
        if (_keyword == "0" || _keyword == "0." || _keyword == "0.0" || _keyword == "0.00") {
            _keyword = "0";
            return true;
        } else {
            var index = _keyword.indexOf("0");
            var length = _keyword.length;
            if (index == 0 && length > 1) {
                var reg = /^[0]{1}[.]{1}[0-9]{1,2}$/;
                if (!reg.test(_keyword)) {
                    return false;
                } else {
                    return true;
                }
            } else {
                var reg = /^[1-9]{1}[0-9]{0,10}[.]{0,1}[0-9]{0,2}$/;
                if (!reg.test(_keyword)) {
                    return false;
                } else {
                    return true;
                }
            }
            return false;
        }
    }

    /*单人价格控制*/
    getid("money").onfocus = function () {
        getid("moneyalert").innerHTML = "";
    };
    getid("money").onchange = function () {
        if (isPriceNumber(getid("money").value)) {
        } else {
            getid("money").value = "";
            getid("moneyalert").innerHTML = "您的输入错误,请输入正常价格";
        }
    };

    /*团购价格*/
    getid("teammoney").onfocus = function () {
        getid("alertteammoney").innerHTML = "";
    };
    getid("teammoney").onchange = function () {
        if (isPriceNumber(getid("money").value)) {
        } else {
            getid("teammoney").value = "";
            getid("alertteammoney").innerHTML = "您的输入错误,请输入正常价格";
        }
    };
    /*人数验证*/
    getid("moneypep").onfocus = function () {
        getid("alertmoneypep").innerHTML = "";
    };
    getid("moneypep").oninput = function () {
        var reg = new RegExp("^[0-9]*$");
        var obj = getid("moneypep").value;
        if (!reg.test(obj)) {

            getid("moneypep").value = "";
            getid("alertmoneypep").innerHTML = "您的输入错误,请输入正整数";
        }

    };
    getid("updata").onclick = function () {
        var s = true;
        for (var i = 0; i < $('.ul>li>input').length; i++) {
            if ($('.ul>li>input')[i].value == "") {

                s = false

            }

            if ($('.item-input>textarea').innerHTML == "") {
                s = false
                alert("团简介不能为空")
            }
            if ($('.alertspan')[i].innerHTML != "") {

                s = false

            }
            var filepath = $("input[name='image']").val();
            var extStart = filepath.lastIndexOf(".");
            var ext=filepath.substring(extStart,filepath.length).toUpperCase();
            if (ext != ".BMP" && ext != ".PNG" && ext != ".GIF" && ext != ".JPG" && ext != ".JPEG") {

                s = false;
                alert("图片有误")
            }
            if (s) {
                $('form').submit()
            }
        }

    }

$('.pull-right').click(function(){
    window.location.reload();
})
};